package com.javaapi.designmode;

interface Fruit {
	public void eat();
	
}

class Apple implements Fruit {
	@Override
	public void eat() {
		System.out.println("eat apple");
	}
}

class Orage implements Fruit {
	@Override
	public void eat() {
		System.out.println("eat oarage");
	}
}

/* 工厂反射机制 */
class Factory {
	public static Fruit createFruit(Class c) {
		Fruit testFactory = null;
		try {
			testFactory = (Fruit) Class.forName(c.getName()).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return testFactory;
	}
}

public class TestFactory {
	public static void main(String args[]) {
		Fruit apple = Factory.createFruit(Apple.class);
		apple.eat();
		Fruit orage = Factory.createFruit(Orage.class);
		orage.eat();
	}
}